﻿<?xml version="1.0" encoding="utf-8" ?>
<Feature id="UserLogin" name="User Login Information" >
		
	<Dependencies>
		<Dependency type="feature">SecurityFeature.xml</Dependency>
		<Dependency type="feature">BizObjTreeFeature.xml</Dependency>
  </Dependencies>
  
  <BusinessRules visibility="public">
	  <BusinessRule name="checkCurrentUserAgainstUiViewName" security="disabled">
		  <Option value="$UserLoginRemoteTier$">
			  <RemoteRule url="$UserLoginRemoteTier$" />
			  <LocalClass name="UserLogin.BusinessRules,ScsCore" />
		  </Option>
	  </BusinessRule>
	  <BusinessRule name="loginAnonymousUser" security="disabled">
		  <Option value="$UserLoginRemoteTier$">
			  <RemoteRule url="$UserLoginRemoteTier$" />
			  <LocalClass name="UserLogin.BusinessRules,ScsCore" />
		  </Option>
	  </BusinessRule>
	  <BusinessRule name="loginUserAdvanced" security="disabled">
		<Option value="$UserLoginRemoteTier$">
			<RemoteRule url="$UserLoginRemoteTier$" />
			<LocalClass name="UserLogin.BusinessRules,ScsCore" />
		</Option>
    </BusinessRule>
	  <BusinessRule name="loginUser" security="disabled">
		<Option value="$UserLoginRemoteTier$">
			<RemoteRule url="$UserLoginRemoteTier$" />
			<LocalClass name="UserLogin.BusinessRules,ScsCore" />
		</Option>
    </BusinessRule>
    <BusinessRule name="logoffUser" security="disabled">
		<Option value="$UserLoginRemoteTier$">
			<RemoteRule url="$UserLoginRemoteTier$" />
			<LocalClass name="UserLogin.BusinessRules,ScsCore" />
		</Option>
    </BusinessRule>
	  
    <BusinessRule name="getCompanyAppFunctions" security="disabled">
		<Option value="$UserLoginRemoteTier$">
			<RemoteRule url="$UserLoginRemoteTier$" />
			<LocalClass name="UserLogin.BusinessRules,ScsCore" />
		</Option>
    </BusinessRule>
	  <BusinessRule name="getPrivilegeLevels" security="disabled">
		  <Option value="$UserLoginRemoteTier$">
			  <RemoteRule url="$UserLoginRemoteTier$" />
			  <LocalClass name="UserLogin.BusinessRules,ScsCore" />
		  </Option>
	  </BusinessRule>
	<BusinessRule name="getCompanyAppFunctionList" security="disabled">
		<Option value="$UserLoginRemoteTier$">
			<RemoteRule url="$UserLoginRemoteTier$" />
			<LocalClass name="UserLogin.BusinessRules,ScsCore" />
		</Option>
    </BusinessRule>
	  <BusinessRule name="getSpecificCompanyAppFunctions" security="disabled">
		  <Option value="$UserLoginRemoteTier$">
			  <RemoteRule url="$UserLoginRemoteTier$" />
			  <LocalClass name="UserLogin.BusinessRules,ScsCore" />
		  </Option>
	  </BusinessRule>
	  
	  <BusinessRule name="getUserLoginOption" security="disabled">
		<Option value="$UserLoginRemoteTier$">
			<RemoteRule url="$UserLoginRemoteTier$" />
			<LocalClass name="UserLogin.BusinessRules,ScsCore" />
		</Option>
    </BusinessRule>
    <BusinessRule name="getRemoteSecurityPrincipal" security="disabled">
		<Option value="$UserLoginRemoteTier$">
			<RemoteRule url="$UserLoginRemoteTier$" />
			<LocalClass name="UserLogin.BusinessRules,ScsCore" />
		</Option>
    </BusinessRule>
    <BusinessRule name="sessionLogoffUser" security="disabled">
		<Option value="$UserLoginRemoteTier$">
			<RemoteRule url="$UserLoginRemoteTier$" />
			<LocalClass name="UserLogin.BusinessRules,ScsCore" />
		</Option>
    </BusinessRule>
    <BusinessRule name="getUserPreferences" security="disabled">
		<Option value="$UserLoginRemoteTier$">
			<RemoteRule url="$UserLoginRemoteTier$" />
			<LocalClass name="UserLogin.BusinessRules,ScsCore" />
		</Option>
    </BusinessRule>
    <BusinessRule name="updateUserPreferences" security="disabled">
		<Option value="$UserLoginRemoteTier$">
			<RemoteRule url="$UserLoginRemoteTier$" />
			<LocalClass name="UserLogin.BusinessRules,ScsCore" />
		</Option>
    </BusinessRule>
    <BusinessRule name="switchActiveCompany" security="disabled">
		<Option value="$UserLoginRemoteTier$">
			<RemoteRule url="$UserLoginRemoteTier$" />
			<LocalClass name="UserLogin.BusinessRules,ScsCore" />
		</Option>
    </BusinessRule>
    <BusinessRule name="getUserLogins" security="disabled">
		<Option value="$UserLoginRemoteTier$">
			<RemoteRule url="$UserLoginRemoteTier$" />
			<LocalClass name="UserLogin.BusinessRules,ScsCore" />
		</Option>
    </BusinessRule>
    <BusinessRule name="getUserLoginTotals" security="disabled">
		<Option value="$UserLoginRemoteTier$">
			<RemoteRule url="$UserLoginRemoteTier$" />
			<LocalClass name="UserLogin.BusinessRules,ScsCore" />
		</Option>
    </BusinessRule>
    <BusinessRule name="updateUserActivity" security="disabled">
		<Option value="$UserLoginRemoteTier$">
			<RemoteRule url="$UserLoginRemoteTier$" />
			<LocalClass name="UserLogin.BusinessRules,ScsCore" />
		</Option>
    </BusinessRule>
  </BusinessRules>
  
	<BusinessRules visibility="private">
		<BusinessRule name="getCompanyByShortName" security="disabled">
			<Option value="$UserLoginRemoteTier$">
				<RemoteRule url="$UserLoginRemoteTier$" />
				<LocalClass name="UserLogin.BusinessRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="getUserAppFunctionPrivilages" security="disabled">
			<Option value="$UserLoginRemoteTier$">
				<RemoteRule url="$UserLoginRemoteTier$" />
				<LocalClass name="UserLogin.BusinessRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="getChildCompanies" security="disabled">
			<Option value="$UserLoginRemoteTier$">
				<RemoteRule url="$UserLoginRemoteTier$" />
				<LocalClass name="UserLogin.BusinessRules,ScsCore" />
			</Option>
		</BusinessRule>
		  <BusinessRule name="getCompanySearchResult" security="disabled">
			  <Option value="$UserLoginRemoteTier$">
				  <RemoteRule url="$UserLoginRemoteTier$" />
				  <LocalClass name="UserLogin.BusinessRules,ScsCore" />
			  </Option>
		  </BusinessRule>
		  <BusinessRule name="getCompany" security="disabled">
			<Option value="$UserLoginRemoteTier$">
				<RemoteRule url="$UserLoginRemoteTier$" />
				<LocalClass name="UserLogin.BusinessRules,ScsCore" />
			</Option>
		</BusinessRule>

		<BusinessRule name="companyIsActive" security="disabled">
			<Option value="$UserLoginRemoteTier$">
				<RemoteRule url="$UserLoginRemoteTier$" />
				<LocalClass name="UserLogin.BusinessRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="getDefaultCompanyId" security="disabled">
			<Option value="$UserLoginRemoteTier$">
				<RemoteRule url="$UserLoginRemoteTier$" />
				<LocalClass name="UserLogin.BusinessRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="getCompanySettingsDbFields" security="disabled">
			<Option value="$UserLoginRemoteTier$">
				<RemoteRule url="$UserLoginRemoteTier$" />
				<LocalClass name="UserLogin.BusinessRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="getCompanyFromDomainName" security="disabled">
			<Option value="$UserLoginRemoteTier$">
				<RemoteRule url="$UserLoginRemoteTier$" />
				<LocalClass name="UserLogin.BusinessRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="getUserSettingsDbFields" security="disabled">
			<Option value="$UserLoginRemoteTier$">
				<RemoteRule url="$UserLoginRemoteTier$" />
				<LocalClass name="UserLogin.BusinessRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="getUserLimitsDbFields" security="disabled">
			<Option value="$UserLoginRemoteTier$">
				<RemoteRule url="$UserLoginRemoteTier$" />
				<LocalClass name="UserLogin.BusinessRules,ScsCore" />
			</Option>
		</BusinessRule>

	</BusinessRules>

	<BusinessRules>
    <BusinessRule name="createCompany" disabled="true" security="disabled" />
    <BusinessRule name="updateCompany" disabled="true" security="disabled" />
  </BusinessRules>

	<BusinessRules>
		<BusinessRule name="getUserSettingsDisplayTemplate" security="disabled">
			<Option value="$UserLoginRemoteTier$">
				<RemoteRule url="$UserLoginRemoteTier$" />
				<LocalClass name="UserLogin.CompanyUserDisplayTemplateBizRules,ScsCore" />
			</Option>
		</BusinessRule>
	</BusinessRules>

<!--
  <BusinessRules>
	<BusinessRule name="setUserLoginResult" postExtends="loginUser" security="disabled" >
		<LocalClass name=" UserLogin.Gui.GuiBizRules, UserLogin.Gui" />
	</BusinessRule>
	<BusinessRule name="setUserLoginResult" postExtends="loginAnonymousUser" security="disabled" >
		<LocalClass name=" UserLogin.Gui.GuiBizRules, UserLogin.Gui" />
	</BusinessRule>
  </BusinessRules>
-->
	<BusinessRules><!--These rules should always be called locally and not remotely-->
		<BusinessRule name="getCachedCompanyInfo" security="disabled">
			<LocalClass name="UserLogin.BusinessRules,ScsCore" />
		</BusinessRule>
	</BusinessRules>

	<BusinessRules><!--These rules should be called on all middle tier servers at the same time.  That means this should be a broadcast call.-->
		<BusinessRule name="clearCachedCompanyInfo" security="disabled">
			<LocalClass name="UserLogin.BusinessRules,ScsCore" />
		</BusinessRule>
	</BusinessRules>
	
	<BusinessObjects>
    <BusinessObject type="AppFunction" key="id">
		<Field name="id" type="String" />
		<Field name="depth" type="Integer" />
		<Field name="description" type="String" />
		<Method name="nitDesc" language="jscript.NET">
			<![CDATA[
				var depth : Int32 = self.getItem("depth");
				var str = "";
				if(depth != 0) {
					var width = depth*25;
					str="#&lt;#div style='margin-left:" + width + "px'#&gt;#" + self.getItem("description") + "#&lt;#/div#&gt;#";
				}
				else if(depth == 0)
					str ="#&lt;#span style='font-weight:bold;font-size:14px;'#&gt;#" + self.getItem("description") + "#&lt;#/span#&gt;#";
				return str;
		]]></Method>
		<Field name="privilege" type="Integer">-1</Field>
    </BusinessObject>

    <BusinessObject type="DynamicAppFunction" extends="AppFunction" key="id">
      <Field name="SpecifierId" type="String" />
    </BusinessObject>

    <BusinessObject type="DynamicAppFunctionSpecifier" key="id">
      <Field name="id" type="String" />
      <Field name="bizrule" type="String" />
      <Field name="bizobjType" type="String" />
      <Field name="scope" type="String">global</Field>

      <Field name="appFunctionGroupId" type="String" />
      <Field name="appFunctionGroupDescription" type="String" />
    </BusinessObject>

    <BusinessObject type="AppFunctionGroup" extends="AppFunction" key="id">
      <Field name="appFunctions" type="List(AppFunction)" />
    </BusinessObject>
	<BusinessObject type="AppFunctionGroupTree" key="id">
		<Field name="id" type="String" />
		<Field name="name" type="String" />
	    <Field name="privilege" type="Integer" />
	</BusinessObject>

	  
	  <BusinessObject type="CompanyLimits" key="id">
		  <Field name="id" type="Guid" />
	  </BusinessObject>

	  <BusinessObject type="UserLimits" key="id">
		  <Field name="id" type="Guid" />
	  </BusinessObject>

	  <BusinessObject type="UserSettings" key="id">
		  <Field name="id" type="Guid" />
		  <Field name="themeName" type="String" />
	  </BusinessObject>

	  <BusinessObject type="CompanySettings" key="id">
		  <Field name="id" type="Guid" />
		  <Field name="autoSignupEnabled" type="Boolean"/>
		  <Field name="maxUser" type="Integer"/>
		  <Field name="maxChildCompany" type="Integer"/>
		  
		  <Field name="sitePath" type="String" />
		  <Field name="domainNames" type="String" />
	  </BusinessObject>

	<BusinessObject type="User" key="id">
		<Field name="id" type="Guid"><NULL/></Field>
		<Field name="userName" type="String"  />
		<Field name="password" type="String" encrypt="true" />
		<Field name="password2" type="String" encrypt="true" />
		<Field name="authenticated" type="Boolean" />
		<Field name="companyId" type ="Guid"><NULL/></Field>
		<Field name="activeCompanyId" type="Guid"><NULL/></Field>
		<Field name="groups" type="List(UserGroup)" />
		<Field name="lastLoginDate" type ="Date" />
		<Field name="dateCreated" type="Date" />
		<Field name="dateUpdated" type="Date" />
		<Field name="enable" type="Boolean" />
		<Field name="verificationId" type="Guid" />
		<Field name="settings" type="UserSettings" />
		<Field name="limits" type="UserLimits" />
		<Field name="isCompanyDefaultAnonymousUser" type="Boolean" />
	</BusinessObject>

	<BusinessObject type="UserGroup" key="id">
		<Field name="id" type="Guid" />
		<Field name="name" type="String" />
		<Field name="description" type ="String" />
		<Field name="autoNotify" type="Boolean" />
		<Field name="systemType" type="Integer" /><!-- 0=generic user group, 1=Company Default Admin Group, 2=Company Default Anon Group-->
		<Field name="appPrivileges" type="List(AppFunction)" />
		<Field name="dateCreated" type ="Date" />
		<Field name="createdBy" type ="Guid" />
		<Field name="dateUpdated" type="Date" />
		<Field name="updatedBy" type="Guid" />
		<Field name="companyId" type="Guid" />
		<Field name="checked" type="Boolean" />	
	</BusinessObject>
	
	<BusinessObject type="Company" key="id" extends="TreeNode">
		<Field name="shortName" type="String" />
		<Field name="anonymousId" type="Guid" />
		<Field name="enable" type="Boolean" />
		<Field name="canCreateChildCompanies" type="Boolean" />
		<Field name="autoCreateUser" type="Boolean" />
	    <Field name="autoCreateCompany" type="Boolean" />
		<Field name="settings" type="CompanySettings" />
		<Field name="limits" type="CompanyLimits" />
    </BusinessObject>
    
    <BusinessObject type="CompanyTreeNode" key="id,parentId" extends="TreeNode" >
      <Field name="enable" type="Boolean" />
    </BusinessObject>
    
    <BusinessObject type="UserLogin" key="sessionId">
      <Field name="sessionId" type="String" />
      <Field name="user" type="User" />
      <Field name="anonUser" type="Boolean" />
      <Field name="loginTime" type="Date" />
      <Field name="lastAccessTime" type="Date" />
      <Field name="browserInfo" type="String" />
      <Field name="referrer" type="String" />
      <Field name="userIPAddresses" type="String" />
      <Field name="checkedIPAddresses" type="Boolean" />
    </BusinessObject>

    <BusinessObject type="UserLoginTotals" key="date">
      <Field name="date" type="Date" />
      <Field name="totalAuthenticatedSessions" type="Integer" />
      <Field name="totalAnonymousSessions" type="Integer" />
      <Method name="totalActualAnonSessions" language="jscript.NET"><![CDATA[
        return (self.getItem("totalAnonymousSessions") - self.getItem("totalAuthenticatedSessions"))
      ]]></Method>
      <Method name="totalUniqueSessions" language="jscript.NET"><![CDATA[
        return (self.getItem("totalAuthenticatedSessions") +
                self.getItem("totalAnonymousSessions") - self.getItem("totalAuthenticatedSessions"))
      ]]></Method>
    </BusinessObject>
  </BusinessObjects>

  <ConfigurationClasses>
    <Class name="sysObjs-UserLogin" type="UserLogin.AppFunctionConfig,ScsCore" />
  </ConfigurationClasses>
	
	<ApplicationFunctions id="UserLogin" description="Company Management">
		<AppFunction id="ManageCompanyConfiguration" description="Manage Company Configuration" />
		<AppFunction id="ManageOwnCompanyDomainNames" description="Manage site domain names" />
		<AppFunction id="ManageUsers" description="Manage Users" />
		<AppFunction id="ManageProfile" description="Manage Own Profile" />
		<AppFunction id="DefaultPrivilege" description="Default Privilege" />
  </ApplicationFunctions>

  <Security>
    <SecurityPrincipal class="Swaf.Security.DynamicResourcesSecurityPrincipal,SwafCore"/>
  </Security>

  <ResourceSets>
    <DynamicResourceSet name="AppFunctions" configPartnerPath="app.sysObjs-UserLogin" />
  </ResourceSets>

  <ApplicationData>
    <Entry name="userLoginOptions" type="Swaf.Container.FlexiMap" />
    <Entry name="userLoginOptions.autoAnonUserLogin" type="System.Boolean">true</Entry>
    <Entry name="userLoginOptions.autoPopulateBlankDataSource" type="System.Boolean">true</Entry>
    <Entry name="userLoginOptions.autoNtlmUserLogin" type="System.Boolean">false</Entry>
    <Entry name="userLoginOptions.anonymousUserId" type="Swaf.BGuid.Guid">{78C4113A-9C2F-4317-AA73-67C027CED0EC}</Entry>
    <Entry name="userLoginOptions.rootCompanyId" type="Swaf.BGuid.Guid">{4A72D2BF-2AB6-463e-A9E2-9E37EDC2A567}</Entry>
	<Entry name="userLoginOptions.defaultPrivilegeLevel" type="Swaf.Security.Privileges,SwafCore">None</Entry>
	<Entry name="userLoginOptions.companySpecificNodeType" type="String">expire after 20 min no use</Entry>
  </ApplicationData>

  <ApplicationEvents>
    <SessionStart>
      <Rule method="loginAnonymousUser" paramHandling="specifiedOnly">
        <Params>
          <Param type="Swaf.BGuid.Guid"><NULL/></Param>
        </Params>
      </Rule>
    </SessionStart>
    <SessionStop>
      <Rule method="sessionLogoffUser" />
    </SessionStop>
  </ApplicationEvents>

	<ClassFactory id="BizProcs">
		<Class type="UserLogin.Gui.UserLoginBizProc,ScsCore" name="userLogin"/>
	</ClassFactory>
	<ClassFactory id="MacroFunctions">
		<Class name="CmpSetting" type="UserLogin.CompanySettingsMacro,ScsCore" />
	</ClassFactory>
	
	<ClassFactory id="TaskTypes">
		<Class type="UserLogin.SpecificUserScheduleTask,ScsCore" name="UserTask" >
			<Pattern>{caseinsensitive}({freqtype}){ws}({unsigned}){ws}({timetype})</Pattern>
			<Pattern>{caseinsensitive}({freqtype}){ws}({unsigned}){ws}({dayweekday}){ws}at{ws}({time})</Pattern>
			<Pattern>{caseinsensitive}({freqtype})(){ws}({dayweekday}){ws}at{ws}({time})</Pattern>
			<Pattern>{caseinsensitive}at{ws}({time})</Pattern>
		</Class>
	</ClassFactory>
	
</Feature>
